Skip to content

feat(aws): Add support for automatic wrapping in ESM #17407

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 25, 2025

Conversation

msonnb
Copy link
Member

@msonnb msonnb commented Aug 13, 2025

This allows code-less setup for Lambda functions running in ESM (and thus the aws-serverless SDK in general) by vendoring the OpenTelemetry AwsLambda instrumentation and wrapping the patched handler with Sentry's wrapHandler.

Comment on lines +30 to +34
responseHook(_span, { err }) {
if (err) {
captureException(err, scope => markEventUnhandled(scope, 'auto.function.aws-serverless.otel'));
}
},
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

capturing errors here ensures that they're connected to the span correctly

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved init code to separate file to avoid circular dependency

@msonnb msonnb self-assigned this Aug 13, 2025
@msonnb msonnb changed the title feat(aws): Support automatic wrapping in ESM feat(aws): Add support for automatic wrapping in ESM Aug 13, 2025
Copy link
Contributor

github-actions bot commented Aug 13, 2025

size-limit report 📦

Path Size % Change Change
@sentry/browser 24.16 kB - -
@sentry/browser - with treeshaking flags 22.73 kB - -
@sentry/browser (incl. Tracing) 39.87 kB - -
@sentry/browser (incl. Tracing, Replay) 77.99 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 67.83 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 82.69 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 94.79 kB - -
@sentry/browser (incl. Feedback) 40.83 kB - -
@sentry/browser (incl. sendFeedback) 28.81 kB - -
@sentry/browser (incl. FeedbackAsync) 33.7 kB - -
@sentry/react 25.88 kB - -
@sentry/react (incl. Tracing) 41.86 kB - -
@sentry/vue 28.64 kB - -
@sentry/vue (incl. Tracing) 41.69 kB - -
@sentry/svelte 24.18 kB - -
CDN Bundle 25.66 kB - -
CDN Bundle (incl. Tracing) 39.76 kB - -
CDN Bundle (incl. Tracing, Replay) 75.82 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 81.27 kB - -
CDN Bundle - uncompressed 74.96 kB - -
CDN Bundle (incl. Tracing) - uncompressed 117.59 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 231.88 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 244.48 kB - -
@sentry/nextjs (client) 43.89 kB - -
@sentry/sveltekit (client) 40.32 kB - -
@sentry/node-core 47.99 kB -0.01% -1 B 🔽
@sentry/node 147.03 kB +0.01% +1 B 🔺
@sentry/node - without tracing 92.24 kB - -
@sentry/aws-serverless 104.46 kB +0.77% +791 B 🔺

View base workflow run

@msonnb msonnb requested review from mydea and andreiborza August 13, 2025 14:40
@msonnb msonnb marked this pull request as ready for review August 13, 2025 14:40
cursor[bot]

This comment was marked as outdated.

Copy link
Member

@andreiborza andreiborza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good stuff! Excited about this.

Comment on lines 61 to 62
const PACKAGE_VERSION = '0.54.0';
const PACKAGE_NAME = '@opentelemetry/instrumentation-aws-lambda';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

l/m: Since this is now our own instrumentation, let's use @sentry/instrumenation-aws-lambda and for version we can import und use SDK_VERSION from @sentry/core, but let's leave a comment that at the time of vendoring we used 0.54.0.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not strictly necessary but probably makes it easier to understand/debug.

@@ -108,58 +59,6 @@ function getRejectedReasons<T>(results: PromiseSettledResult<T>[]): T[] {
}, []);
}

/** */
export function tryPatchHandler(taskRoot: string, handlerPath: string): void {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mhm this is technically a breaking change 🤔

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep it around but no-op + deprecation warning.

@msonnb msonnb force-pushed the ms/aws-esm-auto-wrapping branch from ba931a7 to 3ee810f Compare August 25, 2025 09:33
@msonnb msonnb force-pushed the ms/aws-esm-auto-wrapping branch from 3ee810f to dee487a Compare August 25, 2025 11:57
@msonnb msonnb merged commit f8390ae into develop Aug 25, 2025
184 checks passed
@msonnb msonnb deleted the ms/aws-esm-auto-wrapping branch August 25, 2025 12:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants